package com.kevin.i18n.defaultf.configuration;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

import java.util.List;

@Configuration
public class I18nConfiguration {

    private List<String> basenames;

    public I18nConfiguration() {

    }

    public I18nConfiguration(List<String> basenames) {
        this.basenames = basenames;
    }

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:i18n/messages");
        if (null != basenames && !basenames.isEmpty()) {
            basenames.forEach(messageSource::setBasename);
        }
        return messageSource;
    }

}
